package com.crm.system.service.impl.customerManager;

import com.crm.model.entity.sys.UserAccount;
import com.crm.model.vo.customerManager.CustomerFollowVO;
import com.crm.redis.mapper.ValueRMapper;
import com.crm.service.customerManager.CustomerStatisticsDbService;
import com.crm.system.service.customerManager.CustomerStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author renshaorong
 * @Date 2021/4/28
 */
@Service
@Slf4j
public class CustomerStatisticsServiceImpl implements CustomerStatisticsService {

    @Autowired
    private CustomerStatisticsDbService customerStatisticsDbService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 客户数据指标key
     */
    public static final String GETTIMELIST_LAST_YEAR_KEY = "customer_norm:getTimeList:last_year:customer_last_year";
    public static final String GETTIMELIST_YEAR_KEY = "customer_norm:getTimeList:year:customer_year";
    public static final String GETTIMELIST_MONTH_KEY = "customer_norm:getTimeList:month:customer_month";
    public static final String GETTIMELIST_WEEK_KEY = "customer_norm:getTimeList:week:customer_week";
    public static final String GETTIMELIST_LAST_MONTH_KEY = "customer_norm:getTimeList:last_month:customer_last_month";

    public static final String GETDEALCUSTOMER_LAST_YEAR_KEY = "customer_norm:getDealCustomer:last_year:customer_last_year_";
    public static final String GETDEALCUSTOMER_YEAR_KEY = "customer_norm:getDealCustomer:year:customer_year_";
    public static final String GETDEALCUSTOMER_MONTH_KEY = "customer_norm:getDealCustomer:month:customer_month_";
    public static final String GETDEALCUSTOMER_WEEK_KEY = "customer_norm:getDealCustomer:week:customer_week_";
    public static final String GETDEALCUSTOMER_LAST_MONTH_KEY = "customer_norm:getDealCustomer:last_month:customer_last_month_";

    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_";
    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ZERO_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_zero_";
    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ONE_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_one_";
    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_TWO_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_two_";
    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_THREE_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_three_";
//    public static final String GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_FOUR_KEY = "customer_norm:getCustomerByState:last_year:customer_last_year_four_";

    public static final String GETCUSTOMERBYSTATE_YEAR_KEY = "customer_norm:getCustomerByState:year:customer_year_";
    public static final String GETCUSTOMERBYSTATE_YEAR_TYPE_ZERO_KEY = "customer_norm:getCustomerByState:year:customer_year_zero_";
    public static final String GETCUSTOMERBYSTATE_YEAR_TYPE_ONE_KEY = "customer_norm:getCustomerByState:year:customer_year_one_";
    public static final String GETCUSTOMERBYSTATE_YEAR_TYPE_TWO_KEY = "customer_norm:getCustomerByState:year:customer_year_two_";
    public static final String GETCUSTOMERBYSTATE_YEAR_TYPE_THREE_KEY = "customer_norm:getCustomerByState:year:customer_year_three_";
//    public static final String GETCUSTOMERBYSTATE_YEAR_TYPE_FOUR_KEY = "customer_norm:getCustomerByState:year:customer_year_four_";

    public static final String GETCUSTOMERBYSTATE_MONTH_KEY = "customer_norm:getCustomerByState:month:customer_month_";
    public static final String GETCUSTOMERBYSTATE_MONTH_TYPE_ZERO_KEY = "customer_norm:getCustomerByState:month:customer_month_zero_";
    public static final String GETCUSTOMERBYSTATE_MONTH_TYPE_ONE_KEY = "customer_norm:getCustomerByState:month:customer_month_one_";
    public static final String GETCUSTOMERBYSTATE_MONTH_TYPE_TWO_KEY = "customer_norm:getCustomerByState:month:customer_month_two_";
    public static final String GETCUSTOMERBYSTATE_MONTH_TYPE_THREE_KEY = "customer_norm:getCustomerByState:month:customer_month_three_";
//    public static final String GETCUSTOMERBYSTATE_MONTH_TYPE_FOUR_KEY = "customer_norm:getCustomerByState:month:customer_month_four_";

    public static final String GETCUSTOMERBYSTATE_WEEK_KEY = "customer_norm:getCustomerByState:week:customer_week_";
    public static final String GETCUSTOMERBYSTATE_WEEK_TYPE_ZERO_KEY = "customer_norm:getCustomerByState:week:customer_week_zero_";
    public static final String GETCUSTOMERBYSTATE_WEEK_TYPE_ONE_KEY = "customer_norm:getCustomerByState:week:customer_week_one_";
    public static final String GETCUSTOMERBYSTATE_WEEK_TYPE_TWO_KEY = "customer_norm:getCustomerByState:week:customer_week_two_";
    public static final String GETCUSTOMERBYSTATE_WEEK_TYPE_THREE_KEY = "customer_norm:getCustomerByState:week:customer_week_three_";
//    public static final String GETCUSTOMERBYSTATE_WEEK_TYPE_FOUR_KEY = "customer_norm:getCustomerByState:week:customer_week_four_";

    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_";
    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ZERO_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_zero_";
    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ONE_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_one_";
    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_TWO_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_two_";
    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_THREE_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_three_";
    public static final String GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_FOUR_KEY = "customer_norm:getCustomerByState:last_month:customer_last_month_four_";

    public static final String GETCUSTOMERFOLLOW_ALL_KEY = "customer_norm:getCustomerFollow:all:customer_all_";
    public static final String GETCUSTOMERFOLLOW_ALL_TYPE_ONE_KEY = "customer_norm:getCustomerFollow:all:customer_all_one_";
    public static final String GETCUSTOMERFOLLOW_ALL_TYPE_TWO_KEY = "customer_norm:getCustomerFollow:all:customer_all_two_";
    public static final String GETCUSTOMERFOLLOW_ALL_TYPE_THREE_KEY = "customer_norm:getCustomerFollow:all:customer_all_three_";
    public static final String GETCUSTOMERFOLLOW_ALL_TYPE_FOUR_KEY = "customer_norm:getCustomerFollow:all:customer_all_four_";

    public static final String GETCUSTOMERFOLLOW_YEAR_KEY = "customer_norm:getCustomerFollow:year:customer_year_";
    public static final String GETCUSTOMERFOLLOW_YEAR_TYPE_ONE_KEY = "customer_norm:getCustomerFollow:year:customer_year_one_";
    public static final String GETCUSTOMERFOLLOW_YEAR_TYPE_TWO_KEY = "customer_norm:getCustomerFollow:year:customer_year_two_";
    public static final String GETCUSTOMERFOLLOW_YEAR_TYPE_THREE_KEY = "customer_norm:getCustomerFollow:year:customer_year_three_";
    public static final String GETCUSTOMERFOLLOW_YEAR_TYPE_FOUR_KEY = "customer_norm:getCustomerFollow:year:customer_year_four_";

    public static final String GETCUSTOMERFOLLOW_MONTH_KEY = "customer_norm:getCustomerFollow:month:customer_month_";
    public static final String GETCUSTOMERFOLLOW_MONTH_TYPE_ONE_KEY = "customer_norm:getCustomerFollow:month:customer_month_one_";
    public static final String GETCUSTOMERFOLLOW_MONTH_TYPE_TWO_KEY = "customer_norm:getCustomerFollow:month:customer_month_two_";
    public static final String GETCUSTOMERFOLLOW_MONTH_TYPE_THREE_KEY = "customer_norm:getCustomerFollow:month:customer_month_three_";
    public static final String GETCUSTOMERFOLLOW_MONTH_TYPE_FOUR_KEY = "customer_norm:getCustomerFollow:month:customer_month_four_";

    public static final String GETCUSTOMERFOLLOW_WEEK_KEY = "customer_norm:getCustomerFollow:week:customer_week_";
    public static final String GETCUSTOMERFOLLOW_WEEK_TYPE_ONE_KEY = "customer_norm:getCustomerFollow:week:customer_week_one_";
    public static final String GETCUSTOMERFOLLOW_WEEK_TYPE_TWO_KEY = "customer_norm:getCustomerFollow:week:customer_week_two_";
    public static final String GETCUSTOMERFOLLOW_WEEK_TYPE_THREE_KEY = "customer_norm:getCustomerFollow:week:customer_week_three_";
    public static final String GETCUSTOMERFOLLOW_WEEK_TYPE_FOUR_KEY = "customer_norm:getCustomerFollow:week:customer_week_four_";

    public static final String GETCUSTOMERFOLLOW_LAST_MONTH_KEY = "customer_norm:getCustomerFollow:last_month:customer_last_month_";
    public static final String GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_ONE_KEY = "customer_norm:getCustomerFollow:last_month:customer_last_month_one_";
    public static final String GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_TWO_KEY = "customer_norm:getCustomerFollow:last_month:customer_last_month_two_";
    public static final String GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_THREE_KEY = "customer_norm:getCustomerFollow:last_month:customer_last_month_three_";
    public static final String GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_FOUR_KEY = "customer_norm:getCustomerFollow:last_month:customer_last_month_four_";

    public static final String GETCUSTOMERBUSINESS_EVERY_DAY_KEY = "customer_norm:getCustomerBusiness:customer_every_day_";
    public static final String NONDEALNUMFORMAP_EVERY_DAY_KEY = "customer_norm:nonDealNumForMap:customer_every_day_";
    public static final String HASOPPORTUNITY_EVERY_DAY_KEY = "customer_norm:hasOpportunity:customer_every_day_";
    public static final String CUSTOMERNUM_EVERY_DAY_KEY = "customer_norm:customerNum:customer_every_day_";

    public static final String GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_ONE_KEY = "customer_norm:getCustomerNumForMap:customer_every_day_one_";
    public static final String GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_TWO_KEY = "customer_norm:getCustomerNumForMap:customer_every_day_two_";


    @Override
    public Map<String,Object> getPolyLine(Integer dateUnit) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String companyId = userAccount.getCompanyId();

        try {
            Map<String, Object> resultMap = new HashMap<>();

            switch (dateUnit) {
                //上年 本年 本周 本月 上月
                case 1: { //上年
                    List<Integer> newList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_TWO_KEY+companyId, Integer.class);
                    if (newList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_TWO_KEY+companyId+ "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> renewList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_THREE_KEY+companyId, Integer.class);
                    if (renewList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_THREE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<String> time = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETTIMELIST_LAST_YEAR_KEY, String.class);
                    if (time == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETTIMELIST_LAST_YEAR_KEY + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> intention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ONE_KEY+companyId, Integer.class);
                    if (intention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ONE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> sum = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_YEAR_KEY+companyId, Integer.class);
                    if (sum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_YEAR_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> deal = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETDEALCUSTOMER_LAST_YEAR_KEY+companyId, Integer.class);
                    if (deal == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETDEALCUSTOMER_LAST_YEAR_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> noIntention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ZERO_KEY+companyId, Integer.class);
                    if (noIntention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_YEAR_TYPE_ZERO_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    resultMap.put("time",time);
                    resultMap.put("sum",sum);//客户总数
                    resultMap.put("intention",intention);//意向客户
                    resultMap.put("member",this.getMember(newList,renewList));//会员客户
                    resultMap.put("deal",deal);//成交客户
                    resultMap.put("noIntention",noIntention);//无意向客户
                    resultMap.put("new",newList);//新单客户
                    resultMap.put("renew",renewList);//续费客户
                    return resultMap;
                }

                case 2: { //本年
                    List<Integer> newList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_YEAR_TYPE_TWO_KEY+companyId, Integer.class);
                    if (newList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_YEAR_TYPE_TWO_KEY+companyId+ "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> renewList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_YEAR_TYPE_THREE_KEY+companyId, Integer.class);
                    if (renewList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_YEAR_TYPE_THREE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<String> time = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETTIMELIST_YEAR_KEY, String.class);
                    if (time == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETTIMELIST_YEAR_KEY + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> intention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_YEAR_TYPE_ONE_KEY+companyId, Integer.class);
                    if (intention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_YEAR_TYPE_ONE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> sum = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_YEAR_KEY+companyId, Integer.class);
                    if (sum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_YEAR_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> deal = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETDEALCUSTOMER_YEAR_KEY+companyId, Integer.class);
                    if (deal == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETDEALCUSTOMER_YEAR_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> noIntention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_YEAR_TYPE_ZERO_KEY+companyId, Integer.class);
                    if (noIntention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_YEAR_TYPE_ZERO_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    resultMap.put("time",time);
                    resultMap.put("sum",sum);//客户总数
                    resultMap.put("intention",intention);//意向客户
                    resultMap.put("member",this.getMember(newList,renewList));//会员客户
                    resultMap.put("deal",deal);//成交客户
                    resultMap.put("noIntention",noIntention);//无意向客户
                    resultMap.put("new",newList);//新单客户
                    resultMap.put("renew",renewList);//续费客户
                    return resultMap;
                }

                case 3: { //本周
                    List<Integer> newList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_WEEK_TYPE_TWO_KEY+companyId, Integer.class);
                    if (newList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_WEEK_TYPE_TWO_KEY+companyId+ "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> renewList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_WEEK_TYPE_THREE_KEY+companyId, Integer.class);
                    if (renewList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_WEEK_TYPE_THREE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<String> time = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETTIMELIST_WEEK_KEY, String.class);
                    if (time == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETTIMELIST_WEEK_KEY + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> intention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_WEEK_TYPE_ONE_KEY+companyId, Integer.class);
                    if (intention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_WEEK_TYPE_ONE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> sum = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_WEEK_KEY+companyId, Integer.class);
                    if (sum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_WEEK_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> deal = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETDEALCUSTOMER_WEEK_KEY+companyId, Integer.class);
                    if (deal == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETDEALCUSTOMER_WEEK_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> noIntention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_WEEK_TYPE_ZERO_KEY+companyId, Integer.class);
                    if (noIntention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_WEEK_TYPE_ZERO_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    resultMap.put("time",time);
                    resultMap.put("sum",sum);//客户总数
                    resultMap.put("intention",intention);//意向客户
                    resultMap.put("member",this.getMember(newList,renewList));//会员客户
                    resultMap.put("deal",deal);//成交客户
                    resultMap.put("noIntention",noIntention);//无意向客户
                    resultMap.put("new",newList);//新单客户
                    resultMap.put("renew",renewList);//续费客户
                    return resultMap;
                }

                case 4: { //本月
                    List<Integer> newList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_MONTH_TYPE_TWO_KEY+companyId, Integer.class);
                    if (newList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_MONTH_TYPE_TWO_KEY+companyId+ "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> renewList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_MONTH_TYPE_THREE_KEY+companyId, Integer.class);
                    if (renewList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_MONTH_TYPE_THREE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<String> time = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETTIMELIST_MONTH_KEY, String.class);
                    if (time == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETTIMELIST_MONTH_KEY + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> intention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_MONTH_TYPE_ONE_KEY+companyId, Integer.class);
                    if (intention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_MONTH_TYPE_ONE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> sum = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_MONTH_KEY+companyId, Integer.class);
                    if (sum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_MONTH_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> deal = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETDEALCUSTOMER_MONTH_KEY+companyId, Integer.class);
                    if (deal == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETDEALCUSTOMER_MONTH_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> noIntention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_MONTH_TYPE_ZERO_KEY+companyId, Integer.class);
                    if (noIntention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_MONTH_TYPE_ZERO_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    resultMap.put("time",time);
                    resultMap.put("sum",sum);//客户总数
                    resultMap.put("intention",intention);//意向客户
                    resultMap.put("member",this.getMember(newList,renewList));//会员客户
                    resultMap.put("deal",deal);//成交客户
                    resultMap.put("noIntention",noIntention);//无意向客户
                    resultMap.put("new",newList);//新单客户
                    resultMap.put("renew",renewList);//续费客户
                    return resultMap;
                }

                case 5: { //上月
                    List<Integer> newList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_TWO_KEY+companyId, Integer.class);
                    if (newList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_TWO_KEY+companyId+ "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> renewList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_THREE_KEY+companyId, Integer.class);
                    if (renewList == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_THREE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<String> time = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETTIMELIST_LAST_MONTH_KEY, String.class);
                    if (time == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETTIMELIST_LAST_MONTH_KEY + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> intention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ONE_KEY+companyId, Integer.class);
                    if (intention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ONE_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> sum = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_MONTH_KEY+companyId, Integer.class);
                    if (sum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_MONTH_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> deal = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETDEALCUSTOMER_LAST_MONTH_KEY+companyId, Integer.class);
                    if (deal == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETDEALCUSTOMER_LAST_MONTH_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    List<Integer> noIntention = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ZERO_KEY+companyId, Integer.class);
                    if (noIntention == null) { // redis中无数据，抛出异常，从数据库中读取数据
                        log.error("key为" + GETCUSTOMERBYSTATE_LAST_MONTH_TYPE_ZERO_KEY+companyId + "的值不存在");
                        throw new Exception();
                    }

                    resultMap.put("time",time);
                    resultMap.put("sum",sum);//客户总数
                    resultMap.put("intention",intention);//意向客户
                    resultMap.put("member",this.getMember(newList,renewList));//会员客户
                    resultMap.put("deal",deal);//成交客户
                    resultMap.put("noIntention",noIntention);//无意向客户
                    resultMap.put("new",newList);//新单客户
                    resultMap.put("renew",renewList);//续费客户
                    return resultMap;
                }
                default:
                    throw new Exception();
            }

        }catch (Exception e){
            log.error("客户数据指标中 getPolyLine 方法捕获异常，此处数据从数据库中读取，请检查异常");
            Map<String, Object> resultMap = new HashMap<>();
            List<Integer> newList = customerStatisticsDbService.getCustomerByState(companyId,dateUnit,2);
            List<Integer> renewList = customerStatisticsDbService.getCustomerByState(companyId,dateUnit,3);
            resultMap.put("time",customerStatisticsDbService.getTimeList(dateUnit));
            resultMap.put("sum",customerStatisticsDbService.getCustomerByState(companyId,dateUnit,null));//客户总数
            resultMap.put("intention",customerStatisticsDbService.getCustomerByState(companyId,dateUnit,1));//意向客户
            resultMap.put("member",this.getMember(newList,renewList));//会员客户
            resultMap.put("deal",customerStatisticsDbService.getDealCustomer(companyId,dateUnit));//成交客户
            resultMap.put("noIntention",customerStatisticsDbService.getCustomerByState(companyId,dateUnit,0));//无意向客户
            resultMap.put("new",newList);//新单客户
            resultMap.put("renew",renewList);//续费客户
            return resultMap;
        }
    }

    /**
     * 柱状图数据
     * @return
     *
     * @update 增加两项返回值，修改返回类型List<Integer> 为Map<String,Object>
     * @Author renshaorong
     * @Date 2021/6/3
     */
    @Override
    public Map<String,Object> getCustomerBusiness() {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String companyId = userAccount.getCompanyId();
        try{
            List<Integer> histogram = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERBUSINESS_EVERY_DAY_KEY+companyId, Integer.class);
            if (histogram == null) { // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为" + GETCUSTOMERBUSINESS_EVERY_DAY_KEY+companyId + "的值不存在");
                throw new Exception();
            }

            Integer hasOpportunity = ValueRMapper.getRedisObject(stringRedisTemplate, HASOPPORTUNITY_EVERY_DAY_KEY+companyId, Integer.class);
            if (hasOpportunity == null) { // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为" + HASOPPORTUNITY_EVERY_DAY_KEY+companyId + "的值不存在");
                throw new Exception();
            }
            Integer customerNum = ValueRMapper.getRedisObject(stringRedisTemplate, CUSTOMERNUM_EVERY_DAY_KEY+companyId, Integer.class);
            if (customerNum == null) { // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为" + CUSTOMERNUM_EVERY_DAY_KEY+companyId + "的值不存在");
                throw new Exception();
            }
            Map<String,Object> result = new HashMap<>();
            result.put("histogram",histogram);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(hasOpportunity).append("/").append(customerNum);
            result.put("percentage",stringBuffer);
            result.put("hasNotOpportunity",customerNum-hasOpportunity);
            return result;
        }catch (Exception e){
            log.error("客户数据指标中 getCustomerBusiness 方法捕获异常，此处数据从数据库中读取，请检查异常");
            Map<String,Object> result = new HashMap<>();
            result.put("histogram",customerStatisticsDbService.getCustomerBusiness(companyId));
            StringBuffer stringBuffer = new StringBuffer();
            Integer hasOpportunity = customerStatisticsDbService.hasOpportunity(companyId);
            Integer customerNum = customerStatisticsDbService.customerNum(companyId);
            stringBuffer.append(hasOpportunity).append("/").append(customerNum);
            result.put("percentage",stringBuffer);
            result.put("hasNotOpportunity",customerNum-hasOpportunity);
            return result;
        }
    }

    /**
     * 会员客户=新单客户+续费客户
     * @param newList
     * @param renewList
     * @return
     */
    private List<Integer> getMember(List<Integer> newList, List<Integer> renewList){
        List<Integer> memberList = new ArrayList<>(newList.size());
        for(int i = 0; i < newList.size(); i++){
            memberList.add(newList.get(i) + renewList.get(i));
        }
        return memberList;
    }

    /**
     * 客户跟进意向值
     * @param type
     * @param dateUnit
     * @return
     */
    @Override
    public List<CustomerFollowVO> getCustomerFollow(Integer type, Integer dateUnit) {
        String companyId = ((UserAccount) SecurityUtils.getSubject().getPrincipal()).getCompanyId();//获取登录人所在的公司
        if(type == null){
            type = 0;
        }

        try {
            switch (dateUnit){

                case 1 : { //全部
                    switch (type){
                        case 0 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_ALL_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_ALL_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }

                        case 1 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_ALL_TYPE_ONE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_ALL_TYPE_ONE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 2 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_ALL_TYPE_TWO_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_ALL_TYPE_TWO_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 3 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_ALL_TYPE_THREE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_ALL_TYPE_THREE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 4 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_ALL_TYPE_FOUR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_ALL_TYPE_FOUR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        default:throw new Exception();
                    }

                }

                case 2 : { //本周
                    switch (type){
                        case 0 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_WEEK_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_WEEK_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }

                        case 1 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_WEEK_TYPE_ONE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_WEEK_TYPE_ONE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 2 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_WEEK_TYPE_TWO_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_WEEK_TYPE_TWO_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 3 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_WEEK_TYPE_THREE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_WEEK_TYPE_THREE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 4 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_WEEK_TYPE_FOUR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_WEEK_TYPE_FOUR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        default:throw new Exception();
                    }

                }

                case 3 : { //上月
                    switch (type){
                        case 0 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_LAST_MONTH_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_LAST_MONTH_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }

                        case 1 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_ONE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_ONE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 2 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_TWO_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_TWO_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 3 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_THREE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_THREE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 4 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_FOUR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_LAST_MONTH_TYPE_FOUR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        default:throw new Exception();
                    }

                }

                case 4 : { //本月
                    switch (type){
                        case 0 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_MONTH_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_MONTH_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }

                        case 1 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_MONTH_TYPE_ONE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_MONTH_TYPE_ONE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 2 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_MONTH_TYPE_TWO_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_MONTH_TYPE_TWO_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 3 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_MONTH_TYPE_THREE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_MONTH_TYPE_THREE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 4 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_MONTH_TYPE_FOUR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_MONTH_TYPE_FOUR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        default:throw new Exception();
                    }
                }

                case 5 : { //本年
                    switch (type){
                        case 0 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_YEAR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_YEAR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }

                        case 1 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_YEAR_TYPE_ONE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_YEAR_TYPE_ONE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 2 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_YEAR_TYPE_TWO_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_YEAR_TYPE_TWO_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 3 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_YEAR_TYPE_THREE_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_YEAR_TYPE_THREE_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        case 4 : {
                            List<CustomerFollowVO> customerFollowList = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERFOLLOW_YEAR_TYPE_FOUR_KEY+companyId,CustomerFollowVO.class);
                            if(customerFollowList == null){ // redis中无数据，抛出异常，从数据库中读取数据
                                log.error("key为"+GETCUSTOMERFOLLOW_YEAR_TYPE_FOUR_KEY+companyId+"的值不存在");
                                throw new Exception();
                            }
                            return customerFollowList;
                        }
                        default:throw new Exception();
                    }

                }

                default: throw new Exception();
            }
        }catch (Exception e){
            log.error("客户数据指标中 getCustomerFollow 方法捕获异常，此处数据从数据库中读取，请检查异常");
            return customerStatisticsDbService.getCustomerFollow(companyId, type, dateUnit, null);
        }
    }

    /**
     * 地图数据
     * @return
     */
    @Override
    public Map<String, Object> getMapData() {
        String companyId = ((UserAccount) SecurityUtils.getSubject().getPrincipal()).getCompanyId();

        try {
            Map<String,Object> resultMap = new HashMap<>(2);
            List<Map> nonDeal = ValueRMapper.getRedisObjectList(stringRedisTemplate, NONDEALNUMFORMAP_EVERY_DAY_KEY+companyId,Map.class);
            if(nonDeal == null){ // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为"+NONDEALNUMFORMAP_EVERY_DAY_KEY+companyId+"的值不存在");
                throw new Exception();
            }

            List<Map> member = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_ONE_KEY+companyId,Map.class);
            if(member == null){ // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为"+GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_ONE_KEY+companyId+"的值不存在");
                throw new Exception();
            }

            List<Map> nonMember = ValueRMapper.getRedisObjectList(stringRedisTemplate, GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_TWO_KEY+companyId,Map.class);
            if(nonMember == null){ // redis中无数据，抛出异常，从数据库中读取数据
                log.error("key为"+GETCUSTOMERNUMFORMAP_EVERY_DAY_TYPE_TWO_KEY+companyId+"的值不存在");
                throw new Exception();
            }

            resultMap.put("member",member);//会员
            resultMap.put("nonMember",nonMember);//非会员
            //未成交 = 客户数-成交客户（按是否签订合同计算）
            resultMap.put("nonDeal",nonDeal);
            return resultMap;

        }catch (Exception e){
            log.error("客户数据指标中 getMapData 方法捕获异常，此处数据从数据库中读取，请检查异常");
            Map<String,Object> resultMap = new HashMap<>(2);
            resultMap.put("member",customerStatisticsDbService.getCustomerNumForMap(1,companyId));//会员
            resultMap.put("nonMember",customerStatisticsDbService.getCustomerNumForMap(2,companyId));//非会员
            //未成交 = 客户数-成交客户（按是否签订合同计算）
            resultMap.put("nonDeal",customerStatisticsDbService.nonDealNumForMap(companyId));
            return resultMap;
        }

    }

}
